﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterAdmin.master" AutoEventWireup="true" CodeBehind="Material.aspx.cs" Inherits="Project_Udrinkwater.PagesAdmin.Material" %>
<%@ Register TagPrefix="dxe" Namespace="DevExpress.Web.ASPxEditors" Assembly="DevExpress.Web.v12.2, Version=12.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <dx:ASPxGridViewExporter ID="ASPxGridViewExporter1" runat="server" 
        GridViewID="gvMain">
        <Styles>
            <Default Font-Names="Angsana New">
            </Default>
        </Styles>
    </dx:ASPxGridViewExporter>
    <dx:ASPxGridViewExporter ID="ASPxGridViewExporter2" runat="server" 
        GridViewID="ASPxGridView1">
        <Styles>
            <Default Font-Names="Angsana New">
            </Default>
        </Styles>
    </dx:ASPxGridViewExporter>
    <asp:Panel ID="Panel1" runat="server">
        <table style="width: 100%">
            <tr>
                <td align="right">
                    <dx:ASPxButton ID="ASPxButton1" runat="server" onclick="ASPxButton1_Click" 
                        Text="ค้นหาทั้งหมด">
                    </dx:ASPxButton>
                </td>
            </tr>
        </table>
    </asp:Panel>
    <asp:Panel ID="Panel2" runat="server">
        <fieldset>
        <legend>รายการสั่งซื้อวัตถุดิบ</legend> 
        <asp:Panel ID="Panel6" runat="server">
                        <table style="width: 100%">
                            <tr>
                                <td align="right">
                                    <table style="width: 100%">
                                        <tr>
                                            <td align="right" style="width: 315px; height: 27px;">
                                                <dxe:ASPxLabel ID="ASPxLabel3" runat="server" Text="ค้นหาตั้งแต่วันที่:">
                                                </dxe:ASPxLabel>
                                            </td>
                                            <td style="width: 210px; height: 27px;">
                                                <dxe:ASPxDateEdit ID="deStart0" runat="server" DisplayFormatString="dd/MM/yyyy" 
                                                    EditFormat="Custom" EditFormatString="dd/MM/yyyy">
                                                </dxe:ASPxDateEdit>
                                            </td>
                                            <td align="right" style="width: 108px; height: 27px;">
                                                <dxe:ASPxLabel ID="ASPxLabel4" runat="server" Text="ถึงวันที่:">
                                                </dxe:ASPxLabel>
                                            </td>
                                            <td style="width: 198px; height: 27px;">
                                                <dxe:ASPxDateEdit ID="edEnd0" runat="server" DisplayFormatString="dd/MM/yyyy" 
                                                    EditFormat="Custom" EditFormatString="dd/MM/yyyy">
                                                </dxe:ASPxDateEdit>
                                            </td>
                                            <td style="height: 27px" colspan="2">
                                                <dxe:ASPxButton ID="ASPxButton8" runat="server" onclick="ASPxButton8_Click" 
                                                    Text="ค้นหา">
                                                </dxe:ASPxButton>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="left" style="width: 315px">
                                                <dxe:ASPxButton ID="ASPxButton9" runat="server" onclick="ASPxButton9_Click" 
                                                    Text="ค้นหารายการสั่งซื้อวัตถุดิบแต่ละวัน" Width="200px">
                                                </dxe:ASPxButton>
                                            </td>
                                            <td style="width: 210px">
                                                &nbsp;</td>
                                            <td align="right" style="width: 108px">
                                                &nbsp;</td>
                                            <td style="width: 198px">
                                                &nbsp;</td>
                                            <td align="right">
                                                <dxe:ASPxButton ID="ASPxButton11" runat="server" Text="พิมพ์รายงาน .pdf" 
                                                    onclick="ASPxButton11_Click" Width="120px">
                                                </dxe:ASPxButton>
                                            </td>
                                            <td align="right">
                                                <dxe:ASPxButton ID="ASPxButton13" runat="server" onclick="ASPxButton13_Click" 
                                                    Text="พิมพ์รายงาน .xml" Width="120px">
                                                </dxe:ASPxButton>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </asp:Panel>
        <dx:ASPxGridView ID="gvMain" runat="server" Width="100%" 
            AutoGenerateColumns="False" DataSourceID="SqlMainGV" 
            KeyFieldName="Order_Material_ID">
            <Columns>
                <dx:GridViewDataTextColumn Caption="ดูและทำรายการ" VisibleIndex="6">
                    <EditFormSettings Visible="False" />
                    <DataItemTemplate>
                        <asp:LinkButton ID="LinkButton1"  CommandArgument='<%# Eval("Order_Material_ID") %>' runat="server" oncommand="LinkButton1_Command" 
                            ToolTip="ทำรายการของเอกสารนี้">ดูและทำรายการ</asp:LinkButton>
                    </DataItemTemplate>
                </dx:GridViewDataTextColumn>
                <dx:GridViewCommandColumn VisibleIndex="7" Caption="รายการ">
                    <EditButton Visible="True" Text="แก้ไข">
                    </EditButton>
                    <NewButton Visible="True" Text="เพิ่ม">
                    </NewButton>
                    <DeleteButton Visible="True" Text="ลบ">
                    </DeleteButton>
                    <ClearFilterButton Visible="True">
                    </ClearFilterButton>
                </dx:GridViewCommandColumn>
                <dx:GridViewDataTextColumn FieldName="Order_Material_ID" ReadOnly="True" 
                    VisibleIndex="0" Visible="False">
                    <EditFormSettings Visible="False" />
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn Caption="เลขที่เอกสาร" 
                    FieldName="Order_Material_doc_NO" ReadOnly="True" VisibleIndex="1" 
                    Width="150px">
                    <EditFormSettings Visible="False" />
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataDateColumn Caption="วีนที่เอกสาร" 
                    FieldName="Order_material_Date" VisibleIndex="2">
                    <PropertiesDateEdit DisplayFormatString="dd/MM/yyyy">
                    </PropertiesDateEdit>
                </dx:GridViewDataDateColumn>
                <dx:GridViewDataComboBoxColumn Caption="ชื่อผู้จัดจำหน่าย" FieldName="Supplier_ID" 
                    VisibleIndex="3" Width="250px">
                    <PropertiesComboBox DataSourceID="SqlSubplier" TextField="Supplier_Name" 
                        ValueField="Supplier_ID">
                    </PropertiesComboBox>
                </dx:GridViewDataComboBoxColumn>
                <dx:GridViewDataDateColumn Caption="วันที่กำหนดส่ง" FieldName="Due_Date" 
                    VisibleIndex="4">
                    <PropertiesDateEdit DisplayFormatString="dd/MM/yyyy">
                    </PropertiesDateEdit>
                </dx:GridViewDataDateColumn>
                <dx:GridViewDataTextColumn Caption="เงื่อไนการชำระ" FieldName="Condition_Pay" 
                    VisibleIndex="5" Width="250px">
                </dx:GridViewDataTextColumn>
            </Columns>
            <SettingsPager Mode="ShowAllRecords">
            </SettingsPager>
            <Settings ShowFilterRow="True" />
            <SettingsText GroupPanel="ลากคอลัมมาที่นี่เพื่อจัดเรียงตามคอลัมนั้น" />
        </dx:ASPxGridView>
        </fieldset>
        </asp:Panel>
        <asp:Panel ID="Panel5" runat="server" Visible="False">
            <fieldset>
            <legend>รายการวัตถุดิบแต่ละวัน</legend>
             <table style="width: 100%">
                 <tr>
                     <td align="left" style="width: 315px">
                         <dxe:ASPxButton ID="ASPxButton10" runat="server" onclick="ASPxButton10_Click" 
                             Text="กลับหน้าสั่งซื้อวัตถุดิบ" Width="200px">
                         </dxe:ASPxButton>
                     </td>
                     <td style="width: 210px">
                         &nbsp;</td>
                     <td align="right" style="width: 108px">
                         &nbsp;</td>
                     <td style="width: 198px">
                         &nbsp;</td>
                     <td align="right" colspan="2">
                         &nbsp;</td>
                 </tr>
                 <tr>
                     <td align="right" style="width: 315px">
                         <dxe:ASPxLabel ID="ASPxLabel2" runat="server" Text="ค้นหาตั้งแต่วันที่:">
                         </dxe:ASPxLabel>
                     </td>
                     <td style="width: 210px">
                         <dxe:ASPxDateEdit ID="deStart" runat="server" 
                             DisplayFormatString="dd/MM/yyyy" EditFormat="Custom" 
                             EditFormatString="dd/MM/yyyy">
                         </dxe:ASPxDateEdit>
                     </td>
                     <td align="right" style="width: 108px">
                         <dxe:ASPxLabel ID="ASPxLabel1" runat="server" Text="ถึงวันที่:">
                         </dxe:ASPxLabel>
                     </td>
                     <td style="width: 198px">
                         <dxe:ASPxDateEdit ID="edEnd" runat="server" DisplayFormatString="dd/MM/yyyy" 
                             EditFormat="Custom" EditFormatString="dd/MM/yyyy">
                         </dxe:ASPxDateEdit>
                     </td>
                     <td colspan="2">
                         <dxe:ASPxButton ID="ASPxButton7" runat="server" onclick="ASPxButton7_Click" 
                             Text="ค้นหา">
                         </dxe:ASPxButton>
                     </td>
                 </tr>
                 <tr>
                     <td align="right" style="width: 315px">
                         &nbsp;</td>
                     <td style="width: 210px">
                         &nbsp;</td>
                     <td align="right" style="width: 108px">
                         &nbsp;</td>
                     <td style="width: 198px">
                         &nbsp;</td>
                     <td>
                         <dxe:ASPxButton ID="ASPxButton12" runat="server" onclick="ASPxButton12_Click" 
                             Text="พิมพ์รายงาน .pdf" Width="120px">
                         </dxe:ASPxButton>
                     </td>
                     <td>
                         <dxe:ASPxButton ID="ASPxButton14" runat="server" onclick="ASPxButton14_Click" 
                             Text="พิมพ์รายงาน .xml" Width="120px">
                         </dxe:ASPxButton>
                     </td>
                 </tr>
             </table>
                <dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" 
                    DataSourceID="SqlDataSource1" Width="100%">
                    <TotalSummary>
                        <dx:ASPxSummaryItem DisplayFormat="รวม {0:#,###.00}" FieldName="Total" 
                            ShowInColumn="รวม" ShowInGroupFooterColumn="รวม" SummaryType="Sum" />
                    </TotalSummary>
                    <Columns>
                        <dx:GridViewDataTextColumn Caption="เลขที่เอกสาร" 
                            FieldName="Order_Material_doc_NO" ReadOnly="True" VisibleIndex="0" 
                            Width="100px">
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataDateColumn Caption="วันที่เอกสาร" 
                            FieldName="Order_material_Date" VisibleIndex="1" Width="150px">
                        </dx:GridViewDataDateColumn>
                        <dx:GridViewDataDateColumn Caption="วันที่ส่งมอบ" FieldName="Due_Date" 
                            VisibleIndex="2" Width="100px">
                        </dx:GridViewDataDateColumn>
                        <dx:GridViewDataTextColumn Caption="เงื่อนไขการชำระ" FieldName="Condition_Pay" 
                            VisibleIndex="4" Width="100px">
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn Caption="สินค้า" FieldName="Product_ID" 
                            VisibleIndex="5" Width="150px">
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn Caption="จำนวน" FieldName="Amount" VisibleIndex="7">
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn Caption="ราคา" FieldName="Price" VisibleIndex="6">
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn Caption="ส่วนลด" FieldName="Discount" 
                            VisibleIndex="8">
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn Caption="ผู้จำหน่าย" FieldName="Supplier_Name" 
                            VisibleIndex="3" Width="200px">
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn Caption="รวม" FieldName="Total" ReadOnly="True" 
                            VisibleIndex="9">
                        </dx:GridViewDataTextColumn>
                    </Columns>
                    <SettingsPager Mode="ShowAllRecords">
                    </SettingsPager>
                    <Settings ShowFilterRow="True" ShowFooter="True" />
                </dx:ASPxGridView>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString1 %>" 
                    onselecting="SqlDataSource1_Selecting" SelectCommand="SELECT TB_Order_Material.Order_Material_doc_NO, TB_Order_Material.Order_material_Date, TB_Order_Material.Due_Date, TB_Order_Material.Condition_Pay, TB_Order_Material_List.Product_ID, TB_Order_Material_List.Amount, TB_Order_Material_List.Price, TB_Order_Material_List.Discount, TB_Supplier.Supplier_Name ,(TB_Order_Material_List.Price * TB_Order_Material_List.Amount -TB_Order_Material_List.Discount) AS Total FROM TB_Order_Material INNER JOIN TB_Order_Material_List ON TB_Order_Material.Order_Material_ID = TB_Order_Material_List.Order_Material_ID INNER JOIN TB_Supplier ON TB_Order_Material.Supplier_ID = TB_Supplier.Supplier_ID
WHERE TB_Order_Material.Order_material_Date BETWEEN @sStart And @sEnd
">
                    <SelectParameters>
                        <asp:SessionParameter Name="sStart" SessionField="sStart" />
                        <asp:SessionParameter Name="sEnd" SessionField="sEnd" />
                    </SelectParameters>
                </asp:SqlDataSource>
             </fieldset>
         
        <asp:SqlDataSource ID="SqlMainGV" runat="server" 
            ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>" 
            
            SelectCommand="SELECT Order_Material_ID, Order_Material_doc_NO, Order_material_Date, Supplier_ID, Due_Date, Condition_Pay FROM TB_Order_Material
WHERE Order_material_Date BETWEEN @sStart AND @sEND" 
            DeleteCommand="DELETE FROM TB_Order_Material WHERE (Order_Material_ID = @Order_Material_ID)" 
            InsertCommand="INSERT INTO TB_Order_Material(Order_material_Date, Supplier_ID, Due_Date, Condition_Pay) VALUES (@Order_material_Date, @Supplier_ID, @Due_Date, @Condition_Pay)" 
            
            
            
            
            UpdateCommand="UPDATE TB_Order_Material SET Order_material_Date =@Order_material_Date , Supplier_ID =@Supplier_ID , Due_Date =@Due_Date , Condition_Pay =@Condition_Pay Where  (Order_material_ID=@Order_material_ID) " 
            onselecting="SqlMainGV_Selecting">
            <DeleteParameters>
                <asp:Parameter Name="Order_Material_ID" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="Order_material_Date" />
                <asp:Parameter Name="Supplier_ID" />
                <asp:Parameter Name="Due_Date" />
                <asp:Parameter Name="Condition_Pay" />
            </InsertParameters>
            <SelectParameters>
                <asp:SessionParameter Name="sStart" SessionField="sStart" />
                <asp:SessionParameter Name="sEND" SessionField="sEnd" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="Order_material_Date" />
                <asp:Parameter Name="Supplier_ID" />
                <asp:Parameter Name="Due_Date" />
                <asp:Parameter Name="Condition_Pay" />
                <asp:Parameter Name="Order_material_ID" />
            </UpdateParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlSubplier" runat="server" 
            ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>" 
            SelectCommand="SELECT [Supplier_ID], [Supplier_Name] FROM [TB_Supplier]">
        </asp:SqlDataSource>
    </asp:Panel>
</asp:Content>
